<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
{include file="base/header" /}
<div style="width: 500px;margin: 0 auto;margin-top: 10px;">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 100px">账号</label>
            <div class="layui-input-block">
                <input type="text" onblur="verification()" name="account" required  lay-verify="required" placeholder="账号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"  style="width: 100px">密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required  lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" onblur="mailbox()" required  lay-verify="required" placeholder="邮箱" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">联系人</label>
            <div class="layui-input-block">
                <input type="text" name="linkman" value="0" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">联系电话</label>
            <div class="layui-input-block">
                <input type="text" name="telephone" value="0" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">押金</label>
            <div class="layui-input-block">
                <input type="text" name="bond" required  lay-verify="required" placeholder="押金(元)" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">结算日期</label>
            <div class="layui-input-block">
                <input type="text" name="settlementdate" required  lay-verify="required" value="立即结算" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">结算方式</label>
            <div class="layui-input-block">
                <select name="successively" lay-verify="required">
                    <option value="1">一件代发</option>
                    <option value="2">寄售</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">收款账号</label>
            <div class="layui-input-block">
                <input type="text" name="paymentaccount" value="0" required  lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 100px">所属银行</label>
            <div class="layui-input-block">
                <input type="text" name="bank"  required  value="0" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"style="width: 100px">支行</label>
            <div class="layui-input-block">
                <input type="text" name="branch" required  value="0" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" onclick="insert()" class="btn btn-primary">立即添加</button>
                <button type="button" class="btn btn-warning">重置</button>
            </div>
        </div>
    </form>
</div>

</body>
<script>
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    //添加管理员
    function insert() {
        var account = $("input[name=account]").val();
        var password = $("input[name=password]").val();
        var email = $("input[name=email]").val();
        var linkman = $("input[name=linkman]").val();
        var telephone = $("input[name=telephone]").val();
        var paymentaccount = $("input[name=paymentaccount]").val();
        var bank = $("input[name=bank]").val();
        var branch = $("input[name=branch]").val();
        var settlementdate = $("input[name=settlementdate]").val();
        var successively = $("select[name=successively]").val();
        var bond = $("input[name=bond]").val();
        if(!account){
            layer.alert('账号不能为空');
            return;
        }
        if(!password){
            layer.alert('密码不能为空');
            return;
        }
        if(!email){
            layer.alert('邮箱不能为空');
            return;
        }
        if(!linkman){
            layer.alert('联系人不能为空');
            return;
        }
        if(!telephone){
            layer.alert('电话不能为空');
            return;
        }
        if(!paymentaccount){
            layer.alert('收款账号不能为空');
            return;
        }
        if(!bank){
            layer.alert('所属银行不能为空');
            return;
        }
        if(!branch){
            layer.alert('所属支行不能为空');
            return;
        }
        if(!settlementdate){
            layer.alert('结算方式不能为空');
            return;
        }
        if(!bond){
            layer.alert('押金不能为空');
            return;
        }
        if(isNaN(bond)){
            layer.alert('押金必须是数字');
            return;
        }
        $.ajax({
            url:"{:url('index/account/insert')}",
            data:"account="+account+"&password="+password+"&paymentaccount="+paymentaccount+"&bank="+bank+"&branch="+branch+"&email="+email+"&telephone="+telephone+"&linkman="+linkman+"&settlementdate="+settlementdate+"&successively="+successively,
            type:"post",
            dataType:"json",
            success:function (data) {
                if(data.success){
                    layer.alert(data.success);
                }
                if(data.error){
                    layer.alert(data.error);
                }
            }
        });
    }
    //验证商家账号是否存在
    function verification() {
        var account = $("input[name=account]").val();
        $.ajax({
            url:"{:url('index/account/verification')}",
            data:"account="+account,
            type:"post",
            dataType:"json",
            success:function (data) {
                if(data.success){
                    return;
                }
                if(data.error){
                    layer.alert('用户名：'+account+'  已存在');
                    $("input[name=account]").val("");
                }
            }
        });
    }
    //验证邮箱是否存在
    function mailbox() {
        var email = $("input[name='email']").val();
        $.ajax({
            url:"{:url('index/account/mailbox')}",
            data:"email="+email,
            type:"post",
            dataType:"json",
            success:function (data) {
                if(data.success){
                    return;
                }
                if(data.error){
                    layer.alert("邮箱："+email+" 已存在");
                    $("input[name=email]").val("");
                }
            }
        });
    }
</script>
</html>